﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Communication.Model.configuration;
using Communication.Model.netPacket;
using Communication.Model.packetType;

namespace UI
{
    public partial class TimeSet : Form
    {
        //private ClientManager _cm = null;
        //public TimeSet(ClientManager cm)
        //{
        //    InitializeComponent();
        //    _cm = cm;
        //}
        public TimeSet()
        {
            InitializeComponent();
        }
        private void initial()
        {

        }

        private void TimeSet_Load(object sender, EventArgs e)
        {
            DateTime time = DateTime.Now;
            tb_year.Text = time.Year.ToString();
            tb_month.Text = time.Month.ToString();
            tb_day.Text = time.Day.ToString();
            tb_hour.Text = time.Hour.ToString();
            tb_minute.Text = time.Minute.ToString();
            tb_second.Text = time.Second.ToString();
            tb_milsec.Text = "0";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MachineTime time = new MachineTime();
            time.Year = Convert.ToInt16(tb_year.Text);
            time.Month = Convert.ToByte(tb_month.Text);
            time.Day = Convert.ToByte(tb_day.Text);
            time.Hour = Convert.ToByte(tb_hour.Text);
            time.Minute = Convert.ToByte(tb_minute.Text);
            time.Second = Convert.ToByte(tb_second.Text);
            //time.Millisecond = Convert.ToUInt16(tb_milsec.Text);

            NetPacket timePacket = new NetPacket();
            timePacket.NetPacketHead = new NetPacketHead();
            timePacket.NetPacketHead.PacketType = PacketType.TimeSetting;
            timePacket.DataPacket = time;
            //_cm.SendNetPacket("192.168.2.64", timePacket);
            //_cm.sendString("192.168.2.64", "timesetting");
        }
    }
}
